﻿using HtmlAgilityPack;

namespace HtmlHelper
{
    public static class ParserHtml
    {
        private static readonly HtmlWeb Html = new HtmlWeb();
        /// <summary>
        /// 页面文档
        /// </summary>
        public static HtmlDocument HtmlDoc { get; set; } = new HtmlDocument();

        /// <summary>
        /// 加载网页
        /// </summary>
        /// <param name="url"></param>
        public static HtmlDocument LoadHtml(this string url)
        {
            HtmlDoc.LoadHtml(new GetHtml().HttpGet(url));
            return HtmlDoc;
        }
    }

    public static class ParserNode
    {
        public static HtmlAgilityPack.HtmlNode GetAllNodes(this HtmlDocument dcc)
        {
            return dcc.DocumentNode;
        }

        public static HtmlNodeCollection SelectNode(this HtmlDocument dcc, string xpath)
        {
            return dcc.GetAllNodes().SelectNodes(xpath);
        }
    }
}
